class StoreController < ApplicationController
  before_filter :protect
  
  def requirement
    @re = Requirement.find_by_id(params[:id])
    if @re 
      if @login_user.fav_requirements.include?(@re)
        @str = "已收藏过"
      else
        @login_user.fav_requirements<<@re
        @str = "收藏成功"
      end
    else
      @str = "需求不存在"
    end
  end
  
  def comment
    @cm = Comment.find_by_id(params[:id])
    if @cm 
      if @login_user.fav_comments.include?(@cm)
        @str = "已收藏过"
      else
        @login_user.fav_comments<<@cm
        @str = "收藏成功"
      end
    else
      @str = "回复不存在"
    end
  end
  
  def work
    @work = Work.find_by_id(params[:id])
    if @work 
      if @login_user.fav_works.include?(@work)
        @str = "已收藏过"
      else
        @login_user.fav_works<<@work
        @str = "收藏成功"
      end
    else
      @str = "作品不存在"
    end
  end
  
end
